/**
 * 项目名：五位一体化工安全信息平台
 * 日期：    2019-12-09 17:24:08
 * Copyright (c) 2015- joysuch-版权所有
 */

package com.joysuch.wwyt.bp.controller;

import com.joysuch.wwyt.bp.bean.tagert.*;
import com.joysuch.wwyt.bp.entity.target.BpTargetExamineRecord;
import com.joysuch.wwyt.bp.service.BpTargetDutyService;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.repeatsubmit.NoRepeatSubmit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 安全生产目标责任
 */
@RestController
@RequestMapping("/bp/target/duty")
@Api(tags = "/bp/target/duty 安全生产目标责任")
public class BpTargetDutyController {

    @Autowired
    private BpTargetDutyService bpTargetDutyService;

    @PostMapping("save")
    @ApiOperation("新增/修改")
    @RequiresPermissions("bp:target:duty:save")
    public ResultBean add(@Valid @RequestBody BpTargetDutyBean bean) {
        return bpTargetDutyService.save(bean);
    }

    @GetMapping("get")
    @ApiOperation(value = "单体查询", response = BpTargetDutyDto.class)
    public ResultBean get(Long id) {
        return bpTargetDutyService.get(id);
    }

    @GetMapping("delete")
    @ApiOperation("删除")
    @RequiresPermissions("bp:target:duty:delete")
    public ResultBean delete(Long id) {
        return bpTargetDutyService.delete(id);
    }


    @GetMapping("/deleteMark")
    @ApiOperation(value = "删除数据类型")
    @RequiresPermissions("bp:target:duty:deleteMark")
    public ResultBean deleteMark(@RequestParam Long id){
            bpTargetDutyService.deleteMark(id);
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("page")
    @ApiOperation(value = "分页查询", response = BpTargetPageDto.class)
    public ResultBean page(Pageable pageable, BpTargetQueryBean bean) {
        return bpTargetDutyService.pageType(pageable, bean);
    }

    @GetMapping("submit-audit")
    @ApiOperation("提交审核")
    @RequiresPermissions("bp:target:duty:submit-audit")
    public ResultBean submitAudit(Long id) {
        return bpTargetDutyService.submitAudit(id);
    }

    @GetMapping("audit/{flag}")
    @ApiOperation("审核")
    @RequiresPermissions("bp:target:duty:audit")
    @NoRepeatSubmit(paramNames = "id")
    @ApiImplicitParam(name = "flag", value = "0 不通过; 1 通过", required = true)
    public ResultBean audit(Long id, @PathVariable Integer flag) {
        return bpTargetDutyService.audit(id, flag);
    }

    @GetMapping("examine-record/{flag}")
    @ApiOperation(value = "考核记录", response = BpTargetExamineRecord.class)
    @ApiImplicitParam(name = "flag", value = "0 待考核记录; 1 已考核记录", required = true)
    public ResultBean examineRecord(Long id, @PathVariable Integer flag) {
        return bpTargetDutyService.examineRecord(id, flag);
    }

    @GetMapping("examine-start")
    @ApiOperation(value = "开始考核", response = BpTargetDutyDto.class)
    @RequiresPermissions("bp:target:duty:examine-start")
    public ResultBean examineStart(Long recordId) {
        return bpTargetDutyService.examineStart(recordId);
    }

    @PostMapping("examine-submit")
    @ApiOperation("提交考核结果")
    @RequiresPermissions("bp:target:duty:examine-submit")
    public ResultBean examineSubmit(@Valid @RequestBody BpTargetExamineBean bean) {
        return bpTargetDutyService.examineSubmit(bean);
    }

    @GetMapping("examine-record-detail")
    @ApiOperation(value = "考核记录详情查询", response = BpTargetRecordDto.class)
    public ResultBean examineRecordDetail(Long recordId) {
        return bpTargetDutyService.examineRecordDetail(recordId);
    }


}
